import csv

file_list = ['工作簿5.csv', '工作簿6.csv', '工作簿7.csv']  # CSV文件示例
all_rows = []

# 读取所有CSV文件的数据行（跳过表头）
for i, file_name in enumerate(file_list):
    try:
        with open(file_name, 'r', encoding='utf-8') as f:
            reader = csv.reader(f)
            if i == 0:  # 保留第一个文件的表头
                all_rows.extend(reader)
            else:       # 后续文件跳过表头
                next(reader)  # 跳过标题行
                all_rows.extend(reader)
    except FileNotFoundError:
        print(f"文件 {file_name} 不存在")

# 写入合并后的CSV
with open('merged_data.csv', 'w', newline='', encoding='utf-8') as out_file:
    writer = csv.writer(out_file)
    writer.writerows(all_rows)

print(f"已合并 {len(all_rows)} 行数据到 merged_data.csv")